<template>
  <view class="PageHeader">
    <view class="StatusBar" :style="{ height: `${statusHeight}px` }"></view>
    <view class="Body" :style="{ minHeight: `${minHeight}px` }">
      <view
        :class="{ Back: true, BackDisabled: disabledBack }"
        @click="backClickHandler"
      ></view>
      <slot name="title" />
      <slot name="extra" />
    </view>
  </view>
</template>
<script lang="ts">
import Vue from '@/utils/Vue';
import ProjectUtil from '@/utils/ProjectUtil';

interface IData {}

export default Vue.extend({
  data(): IData {
    return {};
  },
  props: {
    /**
     * 是否禁用返回
     */
    disabledBack: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    backClickHandler() {
      uni.navigateBack({});
    },
  },
  computed: {
    statusHeight() {
      return ProjectUtil.statusHeight();
    },
    minHeight() {
      return ProjectUtil.getWxTitleHeight();
    },
  },
});
</script>
<style lang="less" scoped>
.PageHeader {
  background: #006def;
  font-size: 16px;
  color: white;
  > *:not(:last-child) {
    margin-right: 8px;
  }

  .Body {
    padding: 0 20px;
    display: flex;
    align-items: center;
    .Back {
      padding: 15px 10px;
      padding-left: 0;
      &::after {
        content: '';
        display: block;
        width: 12px;
        height: 12px;
        border: 1px solid white;
        border-top: none;
        border-right: none;
        transform: translateX(50%) rotate(45deg);
      }

      &.BackDisabled {
        visibility: hidden;
        pointer-events: none;
        opacity: 0;
      }
    }
  }
}
</style>
